package com.itheima.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import java.io.BufferedReader;
import java.io.IOException;

@WebFilter("/addServlet")
public class XSSFilter implements Filter {
    public static String params;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        BufferedReader br= request.getReader();
        params = br.readLine();
        System.out.println(params);
        boolean flag = true;
        for (int i = 0; i < params.length(); i++) {
            if (params.charAt(i) == '<'){
                flag = false;
            }
        }
        if (flag){
            chain.doFilter(request,response);
        }else{
            response.getWriter().write("failed");
        }

    }

    @Override
    public void destroy() {

    }
}
